In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib
matplotlib.rcParams['figure.figsize'] = (10.0, 8.0)
import ndreg
from ndreg import preprocessor, util, plotter
import SimpleITK as sitk

Register the data to the ARA


In [2]:
params = {
    # input image path
    'image_path': '../Thy1eYFP_Control_9.tiff',
    # voxel spacing is in mm and corresponds to (x, y, z) spacing
    'image_spacing': (0.04128, 0.04128, 0.04128),
    'image_orientation': 'rpi',
    # the modality can be 'lavision' or 'colm'
    'image_modality': 'lavision',
    'atlas_spacing': (0.05, 0.05, 0.05),
    'atlas_path': '../ARA_50um.tiff',
}

In [3]:
img = util.imgRead(params['image_path'])
img.SetSpacing(params['image_spacing'])
atlas = util.imgRead(params['atlas_path'])
atlas.SetSpacing(params['atlas_spacing'])

In [4]:
img_p = preprocessor.preprocess_brain(img, 
                                      params['atlas_spacing'], 
                                      params['image_modality'],
                                      params['image_orientation'])

In [5]:
atlas_registered = ndreg.register_brain(atlas, img_p)


Step 0: alpha=0.05, beta=0.05, scale=0.0625
	E, E_velocity, E_rate, E_image (E_image %), LearningRate
0.	85226.1, 89.2659, 0, 85136.9 (96.8675%), 2.750000e-03
1.	80573.9, 88.3305, 0, 80485.6 (91.5753%), 1.512500e-03
2.	74680.7, 124.017, 0, 74556.6 (84.8295%), 1.663750e-03
3.	72149.4, 157.015, 0, 71992.4 (81.9119%), 1.830125e-03
4.	70143, 213.898, 0, 69929.1 (79.5643%), 2.013138e-03
5.	68311.6, 280.149, 0, 68031.5 (77.4052%), 2.214451e-03
6.	67836.8, 327.152, 0, 67509.6 (76.8114%), 1.217948e-03
7.	66489.6, 375.896, 0, 66113.7 (75.2231%), 1.339743e-03
8.	66300.1, 440.192, 0, 65859.9 (74.9344%), 1.473717e-03
9.	65347.6, 510.434, 0, 64837.1 (73.7707%), 1.621089e-03
10.	64436.2, 552.761, 0, 63883.5 (72.6857%), 8.915990e-04
11.	63019.6, 599.2, 0, 62420.4 (71.021%), 9.807589e-04
12.	62934.8, 653.686, 0, 62281.2 (70.8626%), 1.078835e-03
13.	62139.4, 719.298, 0, 61420.1 (69.8828%), 1.186718e-03
14.	61947.6, 787.936, 0, 61159.7 (69.5866%), 1.305390e-03
15.	60819.2, 828.633, 0, 59990.6 (68.2564%), 7.179645e-04
16.	60168.3, 872.643, 0, 59295.7 (67.4658%), 7.897610e-04
17.	60070.1, 923.522, 0, 59146.6 (67.2961%), 8.687371e-04
18.	59234.2, 981.149, 0, 58253 (66.2794%), 9.556108e-04
19.	59197.9, 997.114, 0, 58200.8 (66.22%), 2.627930e-04
	E, E_velocity, E_rate, E_image (E_image %), LearningRate
20.	59153.3, 1005.9, 0, 58147.4 (66.1593%), 1.445361e-04
21.	59150.1, 1006.51, 0, 58143.5 (66.1549%), 9.936859e-06
22.	59149.6, 1006.59, 0, 58143 (66.1543%), 1.366318e-06
23.	59149.5, 1006.61, 0, 58142.9 (66.1541%), 3.757375e-07
24.	59149.5, 1006.62, 0, 58142.8 (66.1541%), 5.166390e-08
25.	59149.5, 1006.62, 0, 58142.8 (66.1541%), 2.841515e-08
26.	59149.4, 1006.62, 0, 58142.8 (66.1541%), 1.562833e-08
E = 59199.9 (66.2115%)
Length = 27.2956
Time = 29.0393s (0.483989m)

Step 1: alpha=0.05, beta=0.05, scale=0.125
	E, E_velocity, E_rate, E_image (E_image %), LearningRate
0.	77537.7, 16.3522, 0, 77521.4 (95.9744%), 2.750000e-03
1.	76217.9, 22.1406, 0, 76195.7 (94.3331%), 3.025000e-03
2.	74628.8, 34.2301, 0, 74594.5 (92.3508%), 1.663750e-03
3.	74108.6, 45.7753, 0, 74062.8 (91.6925%), 1.830125e-03
4.	73383, 52.5223, 0, 73330.5 (90.7859%), 1.006569e-03
5.	73012, 61.1659, 0, 72950.8 (90.3158%), 1.107226e-03
6.	72731, 71.4659, 0, 72659.5 (89.9552%), 1.217948e-03
7.	72431, 83.5453, 0, 72347.5 (89.5689%), 1.339743e-03
8.	72107.5, 97.7119, 0, 72009.7 (89.1507%), 1.473717e-03
9.	71732.9, 114.276, 0, 71618.7 (88.6666%), 1.621089e-03
10.	71369.6, 133.725, 0, 71235.9 (88.1927%), 1.783198e-03
11.	70970.4, 156.414, 0, 70814 (87.6703%), 1.961518e-03
12.	70585.2, 182.563, 0, 70402.6 (87.1611%), 2.157670e-03
13.	70232.1, 212.77, 0, 70019.4 (86.6866%), 2.373436e-03
14.	69983.5, 229.968, 0, 69753.5 (86.3574%), 1.305390e-03
15.	69858.2, 248.468, 0, 69609.7 (86.1794%), 1.435929e-03
16.	69705.4, 270.716, 0, 69434.7 (85.9627%), 1.579522e-03
17.	69415.1, 281.707, 0, 69133.4 (85.5897%), 8.687371e-04
18.	69283.5, 295.245, 0, 68988.3 (85.41%), 9.556108e-04
19.	69168.9, 310.181, 0, 68858.7 (85.2496%), 1.051172e-03
	E, E_velocity, E_rate, E_image (E_image %), LearningRate
20.	69031.7, 327.13, 0, 68704.6 (85.0588%), 1.156289e-03
21.	68881.7, 346.079, 0, 68535.6 (84.8497%), 1.271918e-03
22.	68738.9, 367.499, 0, 68371.4 (84.6463%), 1.399110e-03
23.	68573.6, 391.632, 0, 68182 (84.4119%), 1.539021e-03
24.	68383.4, 419.132, 0, 67964.3 (84.1423%), 1.692923e-03
25.	68215.2, 449.953, 0, 67765.2 (83.8959%), 1.862215e-03
26.	68005.3, 485.489, 0, 67519.8 (83.592%), 2.048437e-03
27.	67915.2, 504.402, 0, 67410.8 (83.457%), 1.126640e-03
28.	67743.8, 526.633, 0, 67217.2 (83.2174%), 1.239304e-03
29.	67723, 550.472, 0, 67172.5 (83.1621%), 1.363235e-03
30.	67664.4, 578.677, 0, 67085.7 (83.0546%), 1.499558e-03
31.	67431.4, 592.688, 0, 66838.7 (82.7488%), 8.247569e-04
32.	67311.5, 609.8, 0, 66701.7 (82.5792%), 9.072326e-04
33.	67251.8, 628.292, 0, 66623.5 (82.4824%), 9.979559e-04
34.	67108.9, 649.194, 0, 66459.7 (82.2796%), 1.097751e-03
35.	67058.6, 672.086, 0, 66386.5 (82.1889%), 1.207527e-03
36.	66965.7, 698.153, 0, 66267.5 (82.0417%), 1.328279e-03
37.	66896.1, 712.074, 0, 66184 (81.9382%), 7.305536e-04
38.	66826.4, 727.893, 0, 66098.5 (81.8324%), 8.036089e-04
39.	66741.7, 745.294, 0, 65996.4 (81.706%), 8.839698e-04
	E, E_velocity, E_rate, E_image (E_image %), LearningRate
40.	66699.7, 764.718, 0, 65934.9 (81.6299%), 9.723668e-04
41.	66624.2, 786.19, 0, 65838 (81.5099%), 1.069604e-03
42.	66555.3, 810.172, 0, 65745.1 (81.3949%), 1.176564e-03
43.	66499.3, 836.707, 0, 65662.6 (81.2928%), 1.294220e-03
44.	66407.4, 866.44, 0, 65541 (81.1422%), 1.423642e-03
45.	66336, 899.249, 0, 65436.7 (81.0131%), 1.566006e-03
46.	66235.6, 936.392, 0, 65299.2 (80.8429%), 1.722607e-03
47.	66202.9, 956.16, 0, 65246.8 (80.7779%), 9.474339e-04
48.	66126.7, 979.035, 0, 65147.6 (80.6552%), 1.042177e-03
49.	66081.6, 1003.58, 0, 65078 (80.569%), 1.146395e-03
E = 66081.6 (80.569%)
Length = 25.3828
Time = 49.7044s (0.828407m)

Step 2: alpha=0.05, beta=0.05, scale=0.25
	E, E_velocity, E_rate, E_image (E_image %), LearningRate
0.	63590, 5.51381, 0, 63584.4 (98.1359%), 2.750000e-03
1.	62139.9, 4.54985, 0, 62135.3 (95.8994%), 1.512500e-03
2.	61424.2, 5.51332, 0, 61418.7 (94.7934%), 8.318750e-04
3.	61241.8, 7.13259, 0, 61234.6 (94.5092%), 9.150625e-04
4.	61066, 9.15195, 0, 61056.8 (94.2348%), 1.006569e-03
5.	60913.3, 11.5975, 0, 60901.7 (93.9955%), 1.107226e-03
6.	60754.4, 14.5686, 0, 60739.9 (93.7456%), 1.217948e-03
7.	60600, 18.119, 0, 60581.9 (93.5018%), 1.339743e-03
8.	60414.2, 22.3544, 0, 60391.9 (93.2085%), 1.473717e-03
9.	60217.7, 27.3607, 0, 60190.3 (92.8974%), 1.621089e-03
10.	60031.1, 33.3007, 0, 59997.8 (92.6003%), 1.783198e-03
11.	59893, 40.2738, 0, 59852.8 (92.3765%), 1.961518e-03
12.	59660.5, 48.4703, 0, 59612 (92.0049%), 2.157670e-03
13.	59548.7, 58.2142, 0, 59490.5 (91.8174%), 2.373436e-03
14.	59438.2, 63.7472, 0, 59374.4 (91.6382%), 1.305390e-03
15.	59292.8, 70.0566, 0, 59222.7 (91.4041%), 1.435929e-03
16.	59207.5, 73.5626, 0, 59133.9 (91.267%), 7.897610e-04
17.	59127.6, 77.4861, 0, 59050.1 (91.1376%), 8.687371e-04
18.	59070.2, 81.9044, 0, 58988.3 (91.0422%), 9.556108e-04
19.	59001.5, 86.8365, 0, 58914.7 (90.9287%), 1.051172e-03
	E, E_velocity, E_rate, E_image (E_image %), LearningRate
20.	58931.5, 92.3654, 0, 58839.1 (90.812%), 1.156289e-03
21.	58854.4, 98.5645, 0, 58755.9 (90.6835%), 1.271918e-03
22.	58775.8, 105.535, 0, 58670.3 (90.5515%), 1.399110e-03
23.	58692.3, 113.375, 0, 58579 (90.4105%), 1.539021e-03
24.	58603.2, 122.198, 0, 58481 (90.2593%), 1.692923e-03
25.	58519.5, 132.155, 0, 58387.3 (90.1147%), 1.862215e-03
26.	58426.6, 143.37, 0, 58283.2 (89.9541%), 2.048437e-03
27.	58390, 156.113, 0, 58233.9 (89.8779%), 2.253280e-03
28.	58313.5, 163.056, 0, 58150.5 (89.7492%), 1.239304e-03
29.	58240.4, 171.008, 0, 58069.4 (89.6241%), 1.363235e-03
30.	58198.5, 175.258, 0, 58023.2 (89.5527%), 7.497790e-04
31.	58158.9, 180.063, 0, 57978.8 (89.4842%), 8.247569e-04
32.	58126, 185.397, 0, 57940.6 (89.4253%), 9.072326e-04
33.	58088, 191.316, 0, 57896.7 (89.3575%), 9.979559e-04
34.	58046.8, 197.89, 0, 57848.9 (89.2838%), 1.097751e-03
35.	57999.1, 205.197, 0, 57793.9 (89.1988%), 1.207527e-03
36.	57949.8, 213.325, 0, 57736.4 (89.1101%), 1.328279e-03
37.	57897, 222.378, 0, 57674.6 (89.0148%), 1.461107e-03
38.	57842.2, 232.463, 0, 57609.8 (88.9146%), 1.607218e-03
39.	57782, 243.721, 0, 57538.3 (88.8044%), 1.767940e-03
	E, E_velocity, E_rate, E_image (E_image %), LearningRate
40.	57726.8, 256.296, 0, 57470.5 (88.6997%), 1.944734e-03
41.	57644.9, 270.331, 0, 57374.5 (88.5516%), 2.139207e-03
42.	57629.3, 286.135, 0, 57343.2 (88.5032%), 2.353128e-03
43.	57549.6, 294.788, 0, 57254.8 (88.3668%), 1.294220e-03
44.	57524.1, 304.602, 0, 57219.5 (88.3122%), 1.423642e-03
45.	57508.9, 315.345, 0, 57193.5 (88.2722%), 1.566006e-03
46.	57430.2, 321.303, 0, 57108.9 (88.1416%), 8.613036e-04
47.	57400.7, 327.897, 0, 57072.8 (88.086%), 9.474339e-04
48.	57366.2, 335.201, 0, 57031 (88.0214%), 1.042177e-03
49.	57340, 343.301, 0, 56996.7 (87.9685%), 1.146395e-03
E = 57340 (87.9685%)
Length = 13.3366
Time = 99.0092s (1.65015m)

Step 3: alpha=0.05, beta=0.05, scale=0.5
	E, E_velocity, E_rate, E_image (E_image %), LearningRate
0.	60386.6, 3.89657, 0, 60382.7 (95.7794%), 5.500000e-03
E = 60386.6 (95.7794%)
Length = 2.49854
Time = 55.6604s (0.927673m)

Step 4: alpha=0.05, beta=0.05, scale=1.0
	E, E_velocity, E_rate, E_image (E_image %), LearningRate
0.	57955.2, 6.81996, 0, 57948.3 (99.4014%), 2.750000e-03
1.	57196.9, 3.03574, 0, 57193.9 (98.1072%), 1.512500e-03
2.	55397.7, 1.80926, 0, 55395.9 (95.0231%), 8.318750e-04
E = 55397.7 (95.0231%)
Length = 1.76762
Time = 423.794s (7.06323m)

Detect cells in chunks


In [4]:
path_to_chunks = './test_data_cobalt/cell_detection_chunks/'

In [5]:
from cell_detector import *

In [6]:
def detect_all_cells(chunks, csv_path): 
    threshold=1.0
    jobs=1
    verbose=0
    max_val_ = get_max_intensity(chunks)
    paired_files = get_paired_files(chunks)
    for i in tqdm(paired_files, desc='detecting cells...'):
        detect_cells(i,csv_path,threshold, max_val=max_val_, verbose=verbose)
    centroids = get_cells_from_csv(csv_path)
    centroids_t = prune_clusters(centroids[:,:3], verbose=verbose)
    write_list_to_csv(centroids_t, csv_path, open_mode='w')

In [ ]:
detect_all_cells(path_to_chunks, './test1.csv')


finding max intensity over all chunks: 100%|██████████| 2/2 [00:00<00:00,  9.24it/s]
detecting cells...:   0%|          | 0/1 [00:00<?, ?it/s]

quantification of results


In [ ]:


In [ ]:


In [ ]: